﻿using System;
using System.Security.Cryptography;

namespace Transforms.Core
{

    public class Identity
    {
        public byte[] Key { get; private set; }

        public byte[] IV { get; private set; }

        public Identity(byte[] key, byte[] iv)
        {
            Key = key;
            IV = iv;
        }

        public byte[] Compose(byte[] key)
        {
            //throw new NotImplementedException();

            // TODO: real saver
            var result = new byte[Key.Length + IV.Length];
            Buffer.BlockCopy(Key, 0, result, 0, Key.Length);
            Buffer.BlockCopy(IV, 0, result, Key.Length, IV.Length);
            return result;
        }

        public static Identity Generate()
        {
            using (var aes = new RijndaelManaged { Mode = CipherMode.CBC })
            {
                aes.GenerateKey();
                aes.GenerateIV();

                return new Identity(aes.Key, aes.IV);
            }
        }
    }
}